package com.itheima.manager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.OrderReturnReason;
import com.itheima.service.IOrderReturnReasonService;
import com.itheima.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;

import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
@Component
public class OrderReturnReasonManager {
    @DubboReference
    private IOrderReturnReasonService orderReturnReasonService;
    //分页查询退货原因
    public PageResult list(Integer pageNum, Integer pageSize) {
        Page page = orderReturnReasonService.selectByPage(pageNum, pageSize);
        return new PageResult(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords());
    }

    //根据id，获取单个退货原因详情信息
    public OrderReturnReason select(Long id) {
        return orderReturnReasonService.findById(id);
    }

    //修改退货原因
    public Integer updateReturnReason(Long id, OrderReturnReason reason) {
        return orderReturnReasonService.updateReturnReason(reason);
    }

    //修改退货原因启用状态
    public Integer updateStatus(Long id, Integer status) {
        OrderReturnReason orderReturnReason = new OrderReturnReason();
        orderReturnReason.setId(id);
        orderReturnReason.setStatus(status);
        return orderReturnReasonService.updateReturnReason(orderReturnReason);
    }

    //批量删除退货原因
    public Integer delete(List<Long> ids) {
        return orderReturnReasonService.deleteByIds(ids);
    }

    //添加退货原因
    public Integer create(OrderReturnReason reason) {
       // reason.setCreateTime(LocalDateTime.now());
        return orderReturnReasonService.saveReson(reason);
    }
}
